from os import makedirs

import requests
import re
from bs4 import BeautifulSoup
from contextlib import closing

from os.path import exists
import sys

sys.setrecursionlimit(1000000)


def req_get_bf(url):
    return BeautifulSoup(requests.get(url, timeout=180).text, 'html.parser')


def just_url(temp_url, detail_name):
    temp_bf = req_get_bf(temp_url)
    useragents = temp_bf.find_all('pre', 'wp-block-preformatted')
    if useragents:
        for agent in useragents:
            string = agent.string.replace("&nbsp;", "").replace(" ", "")
            print(string)
            with open('tag.txt', 'a') as file_object:  # windows 系统中 ，路径间隔符号是反斜杠 \
                file_object.write(string)
                file_object.write("\n")


if __name__ == '__main__':
    html = "https://tiktoktip.com/tiktok-hashtags/"
    just_url(html, 'home')
